<?php
$has_cust_inv = $this->requestAction('supplier_admins/has_cust_inventories');

// ดูว่า Supplier นี้มีเก็บคลังลูกค้าไว้ที่ Supplier เองหรือไม่
$customers = $this->requestAction('supplier_admins/has_supplier_inventories');
?>


<td class="rootVoice ui-corner-top <?php echo $parentNav == 'users' ? 'ui-state-active nav-actived ' : null; ?>"><?php echo $html->link('Home', '/users/home'); ?></td>
<?php if ($has_cust_inv) { ?>
    <td class="rootVoice ui-corner-top <?php echo $parentNav == 'supplier_consignment_lists' ? 'ui-state-active nav-actived ' : null; ?>"><?php echo $html->link('Inventory List', '/supplier_consignment_lists'); ?></td>
    <td class="rootVoice ui-corner-top <?php echo $parentNav == 'supplier_dispatches' ? 'ui-state-active nav-actived ' : null; ?>"><?php echo $html->link('Dispatch', '/supplier_dispatches'); ?></td>
<?php } ?>
<td class="partition"></td>
<?php
if ($customers != null) {
    ?>
    <td class="rootVoice {menu: 'supplier_inventory'} <?php echo $parentNav == 'supplier_inventories' ? 'ui-state-active nav-actived ' : null; ?>">Customer Inventory</td>
    <td class="rootVoice ui-corner-top <?php echo $parentNav == 'supplier_stocks_in' ? 'ui-state-active nav-actived ' : null; ?>"><?php echo $html->link('Invent. In', '/supplier_stocks_in'); ?></td>
    <td class="rootVoice ui-corner-top <?php echo $parentNav == 'supplier_delivery_requests' ? 'ui-state-active nav-actived ' : null; ?>">
    <?php
        $count = $this->requestAction('supplier_delivery_requests/get_on_request_count');
    echo $html->link('Delivery Request' . ($count > 0? ' (' . $count . ')': ''), '/supplier_delivery_requests');
    ?>
    </td>
    <td class="rootVoice ui-corner-top <?php echo $parentNav == 'supplier_stocks_out' ? 'ui-state-active nav-actived ' : null; ?>"><?php echo $html->link('Invent. Out', '/supplier_stocks_out'); ?></td>
    <td class="partition"></td>
<?php } ?>
<td class="rootVoice {menu: 'supplier_return'} <?php echo $parentNav == 'main_supplier_returns' ? 'ui-state-active nav-actived ' : null; ?>">Return</td>
<?php if ($session->read('Auth.User.read_message') == true) : ?>
    <td class="rootVoice ui-corner-top <?php echo $parentNav == 'messages' ? 'ui-state-active nav-actived ' : null; ?>"><?php echo $html->link('Message' . (($message_count = $this->requestAction('messages/new_message_count')) > 0 ? ' (' . $message_count . ')' : ''), '/messages'); ?></td>
<?php endif; ?>
<?php if ($session->read('Auth.User.supplier_report') == true) : ?>
    <td class="rootVoice {menu: 'supplier_report'} <?php echo $parentNav == 'main_supplier_report' ? 'ui-state-active nav-actived ' : null; ?>">Report</td>
<?php endif; ?>
<td class="rootVoice {menu: 'supplier_manage'} <?php echo $parentNav == 'supplier_admins' ? 'ui-state-active nav-actived ' : null; ?>">Manage</td>

<!-- sub menu -->
<div id="supplier_manage" class="mbmenu">
    <?php echo $html->link('Customer', array('controller' => 'supplier_customers', 'action' => 'display')); ?>
    <?php echo $html->link('User', array('controller' => 'supplier_users', 'action' => 'display')); ?>
</div>

<div id="supplier_inventory" class="mbmenu">
    <?php
    foreach ($customers as $cust) {
        echo $html->link($cust['Customer']['name'], array('controller' => 'supplier_inventories', 'action' => 'display', $cust['Customer']['id']));
    }
    ?>
</div>

<div id="supplier_report" class="mbmenu">
    <a class="{menu: 'sub_menu_supplier_report'}">Vendor</a>
    <a class="{menu: 'sub_menu_customer_report'}">Customer</a>
</div>

<div id="sub_menu_supplier_report" class="menu hide">
    <?php echo $html->link('Dispatch', array('controller' => 'supplier_reports', 'action' => 'dispatch_search')); ?>
</div>

<div id="sub_menu_customer_report" class="menu hide">
    <?php echo $html->link('Stock in', array('controller' => 'supplier_reports', 'action' => 'cust_stock_in_search')); ?>
    <a class="{menu: 'sub_menu_customer_report_stock_out'}">Stock out</a>
</div>

<div id="sub_menu_customer_report_stock_out" class="menu hide">
    <?php echo $html->link('Group by Cost Center', array('controller' => 'supplier_reports', 'action' => 'cust_stock_out_cost_center_search')); ?>
    <?php echo $html->link('Group by Part', array('controller' => 'supplier_reports', 'action' => 'cust_stock_out_search')); ?>
</div>

<div id="supplier_return" class="menu hide">
    <?php
    if ($has_cust_inv) {
        echo $html->link('Dispatch Return', array('controller' => 'supplier_dispatch_returns', 'action' => 'display'));
        echo $html->link('Customer Return', array('controller' => 'supplier_retrieves', 'action' => 'display'));
    }
    if ($customers != null) {
        echo $html->link('Delivery Return', array('controller' => 'supplier_delivery_returns', 'action' => 'display'));
    }
    ?>
</div>
